from itsdangerous import TimedJSONWebSignatureSerializer as TJWSS, BadData
from django.conf import settings


def generate_openid_sign(openid):
    tjwss = TJWSS(secret_key = settings.SECRET_KEY, expires_in = 600)
    data = {'openid': openid}
    token = tjwss.dumps(data)
    return token


def check_openid(token):
    tjwss = TJWSS(secret_key = settings.SECRET_KEY, expires_in = 600)
    try:
        data = tjwss.loads(token)
        return data.get('openid')
    except BadData:
        return None